package com.lizhangjun.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lizhangjun.domain.QChannel;
import com.lizhangjun.entity.Result;
import com.lizhangjun.service.QChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhangjun
 * @since 2021-06-23
 */
@Api(tags = {"频道相关接口"} )
@RestController
@RequiredArgsConstructor
@RequestMapping("/q-channel")
public class QChannelController {

    private final QChannelService channelService;

    /**
     * 添加频道
     * @param channel 频道
     * @return 是否添加成功
     */
    @ApiOperation("添加频道")
    @PostMapping("/add")
    public Result add(@RequestBody QChannel channel){
        if(channelService.saveOrUpdate(channel)){
            return Result.success();
        }else{
            return Result.fail("添加频道失败");
        }
    }

    /**
     * 查找所有频道
     * @return 频道
     */
    @ApiOperation("查找所有频道")
    @GetMapping("/list")
    public Result list(){
        return Result.success(channelService.list());
    }

    /**
     * 查找前8个热门频道
     * @return 频道
     */
    @ApiOperation("查找前8个热门频道")
    @GetMapping("/nav")
    public Result nav(){
        LambdaQueryWrapper<QChannel> wrapper = new LambdaQueryWrapper<>();
        wrapper.last("limit 8");
        return Result.success(channelService.list(wrapper));
    }
}

